<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>index.html</title>
	#style
</head>
 <body class="easyui-layout">
 <script type="text/javascript">
 	var winPlanAdd = new Windows("win_work_plan_add");
 	var winPlanEdit = new Windows("win_work_plan_edit");
	$(function(){
	     initDataGrid();
	     initWindows();
	     initToolbar();
	});
	function initDataGrid(){
		$("#dgPlanList").datagrid({
			autoRowHeight: false,
			collapsible:true,
			url:"${basePath}/admin/work/plan/list",
			sortName: "id",
			sortOrder: "asc",
			remoteSort: true,
			border:false,
			fit:true,
			idField:"id",
			frozenColumns:[[
				{field:"ck",checkbox:true},
				{field:"id",hidden:true}
			]],
			columns:[[
				{title:"任务",field:"title",width:300},
				{title:"执行人",field:"executor",width:80,sortable:true},
				{title:"开始时间",field:"startTime",width:100,sortable:true},
				{title:"结束时间",field:"endTime",width:100,sortable:true},
				{title:"实际完成时间",field:"completeTime",width:150,sortable:true},
				{title:"剩余工期(距今)",field:"days",width:90,sortable:true,formatter:function(value,row,index){
					var now = new Date();
					var endDate = DateUtil.parse(row.endTime);
					value = (now.getTime()-endDate.getTime())/(24*60*60*1000);
					if(value >= 0){
						value = "0天";
					}else{
						value = Math.abs(value).toString();
						if(value.length>3){
							value = value.substring(0, 3);
						}
						value += "天";
					}
					return value;
				}},
				{title:"描述",field:"descript",width:200},
				{title:"状态",field:"state",width:50,sortable:true,formatter:function(value,row,index){
					if(value == 1){
						value = "<span style='color:#FFD306'>待办</span>";
					}else if(value == 2){
						value = "进行中";
					}else if(value == 3){
						value = "<span style='color:#00BB00'>完成</span>";
					}else if(value == 4){
						value = "<span style='color:#ccc'>关闭</span>";
					}else if(value == 5){
						value = "<span style='color:red'>延期</span>";
					}
					return value;
				}}
			]],
			pagination:true,
			rownumbers:true,
			toolbar:"#dgPlanList-toolbar",
			onRowContextMenu:function(e,rowindex,rowData){
				rowContentMenuShowHandler(e,rowindex,rowData,"dgPlanList","dgPlanList_rowContextMenu");
			},
			onDblClickRow:function(rowindex,rowdata){
				winPlanEdit.windows({href:"${basePath}/admin/work/plan/edit/"+rowdata.id});
				winPlanEdit.open();
			}
		});
	}
	function initWindows(){
		winPlanAdd.windows({
			title:"新增计划",
			width:450,
			height:300,
			modal:true,
			cache:false,
			closed:true,
			iconCls:"icon-add",
			href:"${basePath}/admin/work/plan/add",
			onClose:function(){
				if(winPlanAdd.getReturnValue()=="true"){
					$("#dgPlanList").datagrid("reload");
				}
			}
		});
		winPlanEdit.windows({
			title:"修改计划",
			width:450,
			height:300,
			modal:true,
			cache:false,
			closed:true,
			iconCls:"icon-edit",
			href:"${basePath}/admin/work/plan/edit",
			onClose:function(){
				if(winPlanEdit.getReturnValue()=="true"){
					$("#dgPlanList").datagrid("reload");
				}
			}
		});
	}
	function initToolbar(){
		$("#btnAdd").click(function(){
			winPlanAdd.open();
		});
		$("#btnEdit").click(function(){
			var selectId = DataGridUtil.getSelectionsId($("#dgPlanList"));
			if(selectId){
				winPlanEdit.setHref("$!basePath/admin/work/plan/edit/"+selectId);
				winPlanEdit.open();
			}else{
				top.Notiy.warning("请选择要修改的计划!");
			}
			
		});
		$("#btnRemove").attr("deleteUrl","$!basePath/admin/work/plan/doDelete");
		$("#btnRemove").click(function(){
			DataGridUtil.Delete("$!basePath/admin/work/plan/doDelete","dgPlanList");
		});
		$("#btnExportExcel").click(function(){
			DataGridUtil.exportExcel($("#dgPlanList"),"Plan");
		});
		$("#btnComplete").click(function(){
			var selectIds = DataGridUtil.getSelectionsIds($("#dgPlanList"));
			if(selectIds.length == 0){
				top.Notiy.warning("请选择要标记为完成的计划！");
				return;
			}
			jQuery.post("$!basePath/admin/work/plan/doComplete",{ids:selectIds.toString()},function(data){
				if(data.success == true){
					top.Notiy.success("计划已标记为完成！");
					$("#dgPlanList").datagrid("reload");
				}else{
					top.Dialog.error(data.error);
				}
			},"json");
		});
		$("#btnClose").click(function(){
			var selectIds = DataGridUtil.getSelectionsIds($("#dgPlanList"));
			if(selectIds.length == 0){
				top.Notiy.warning("请选择要标记为完成的计划！");
				return;
			}
			jQuery.post("$!basePath/admin/work/plan/doClose",{ids:selectIds.toString()},function(data){
				if(data.success == true){
					top.Notiy.success("计划已关闭！");
					$("#dgPlanList").datagrid("reload");
				}else{
					top.Dialog.error(data.error);
				}
			},"json");
		});
		$("#btnNormal").click(function(){
			var selectIds = DataGridUtil.getSelectionsIds($("#dgPlanList"));
			if(selectIds.length == 0){
				top.Notiy.warning("请选择要标记为进行中的计划！");
				return;
			}
			jQuery.post("$!basePath/admin/work/plan/doNormal",{ids:selectIds.toString()},function(data){
				if(data.success == true){
					top.Notiy.success("计划标记为进行中！");
					$("#dgPlanList").datagrid("reload");
				}else{
					top.Dialog.error(data.error);
				}
			},"json");
		});
		$("#btnFilterComplete").click(function(){
			var text = $(this).linkbutton("getText");
			if(text == "不显示已完成"){
				$("#dgPlanList").datagrid("load",{name:"filterComplete",value:"true"});
				$(this).linkbutton("setText","显示已完成");
			}else{
				$("#dgPlanList").datagrid("load",{name:"filterComplete",value:"false"});
				$(this).linkbutton("setText","不显示已完成");
			}
		});
	}
	function doEditForContentMenu_btnEdit(param){
		winPlanEdit.setHref("$!basePath/admin/work/plan/edit/"+param);
		winPlanEdit.open();
	}
	function rowContentMenuClickHandler(item){
		ContentMenuClickHandler("dgPlanList",item);
	}
	function doSearch(v,n){
		doDataGridSearch("dgPlanList",n,v);
	}
 </script>
    <div data-options="region:'center',border:true">
		<table id="dgPlanList"></table>
    </div>
    <!--Tools And ContextMenu-->
    <div id="dgPlanList-toolbar" style="padding:2px 0;" class="datagrid-toolbar">
		<table cellpadding="0" cellspacing="0" style="width:100%">
			<tr>
				<td style="padding-left:2px">
					<a id="btnAdd" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" style="float: left;">新增计划</a>
					<a id="btnEdit" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" style="float: left;">修改计划</a>
					<a id="btnRemove" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" style="float: left;">删除计划</a>
					<div class="datagrid-btn-separator"></div>
					<a id="btnComplete" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true" style="float: left;">标记为完成</a>
					<a id="btnNormal" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-flag-blue',plain:true" style="float: left;">标记为进行中</a>
					<a id="btnClose" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" style="float: left;">关闭计划</a>
					<div class="datagrid-btn-separator"></div>
					<a id="btnFilterComplete" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-flag-red',plain:true" style="float: left;">不显示已完成</a>
					<div class="datagrid-btn-separator"></div>
					<a id="btnExportExcel" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-export-excel',plain:true" style="float: left;">导出Excel</a>
					<div class="datagrid-btn-separator"></div>
					<select class="easyui-combobox" data-options="width:80,onChange:function(newVal,oldVal){
						if(newVal != -1){
							$('#dgPlanList').datagrid('load',{name:'state',value:newVal});
						}else{
							$('#dgPlanList').datagrid('load',{name:'',value:''});
						}
					}">
						<option value="-1" selected="selected">全部</option>
						<option value="1">待办</option>
						<option value="2">进行中</option>
						<option value="3">完成</option>
						<option value="4">关闭</option>
						<option value="5">延期</option>
					</select>
				</td>
				<td style="text-align:right;padding-right:2px">
					<input id="ss" style="width:240px;" class="easyui-searchbox" data-options="searcher:doSearch,prompt:'请输入查询内容',menu:'#ss_mm'"></input>
					<div id="ss_mm" style="width:80px;">
						<div data-options="name:'title'">任务名称</div>
						<div data-options="name:'startTime'">开始时间</div>
						<div data-options="name:'endTime'">结束时间</div>
						<div data-options="name:'executor'">执行人</div>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<!-- 邮件菜单 -->
	<div id="dgPlanList_rowContextMenu" data-options="onClick:rowContentMenuClickHandler" class="easyui-menu" style="width:120px;">
		<div name="select" data-options="iconCls:'icon-ok'">选中</div>
		<div name="edit" data-options="iconCls:'icon-edit'" with="btnEdit">修改该计划</div>
		<div name="remove" data-options="iconCls:'icon-remove'" with="btnRemove">删除该计划</div>
		<div name="removeSelected" data-options="iconCls:'icon-remove'" with="btnRemove">删除选中的计划</div>
		<div name="complete" data-options="iconCls:'icon-ok'" with="btnComplete">标记为完成</div>
		<div name="close" data-options="iconCls:'icon-cancel'" with="btnClose">关闭计划</div>
		<div name="normal" data-options="iconCls:'icon-flag-blue'" with="btnNormal">标记为进行中</div>
	</div>
  </body>
</html>
